package wrs.hcs.tc;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;

import wrs.hcs.functions.*;

public class WebAdmin_SingleNoPin {
	
	public static WebDriver driver;
	public static String pin1, pin2, mainWindow;
	
	static
	Webdriver d = new Webdriver();
	Login log = new Login();
	Logout out = new Logout();
	AdminConsole console = new AdminConsole();
	AdminConsole_Tracker act = new AdminConsole_Tracker();
	Miscellaneous m = new Miscellaneous();
	Hcs_Admission adm = new Hcs_Admission();
	Transactions_WithAddOns twa = new Transactions_WithAddOns();
	
	public void inpatient() throws Exception
	{
		driver = d.startUp();
		log.admin(driver); 																										//login
		String returned_string = console.create_single_inpatient_with_no_pin_in_admin(driver, "onlinecardio", false);   		//update on admin and forward to hcs
		String[] arrString = returned_string.split(",");
		String lastName = arrString[0];
		String firstName = arrString[1];
		String admDate = arrString[2];

		String mainWindow = console.window_main_focus(driver);
		console.wellness_search_it(driver, lastName, firstName, admDate);
		console.get_status_and_click(driver, firstName, false);
		String text = m.set_dropdown_to_hcs("queue");
		console.select_dropdown_to_hcs(driver, text, "single");
		driver.switchTo().window(mainWindow);
		console.display_message_to_hcs(driver);
		console.wellness_search_it(driver, lastName, firstName, admDate);
		pin1 = console.get_status_and_click(driver, "", false);
		act.goto_result_tracker(driver);
		act.tracker(driver, pin1);
		out.admin(driver);
		
		log.hcs(driver, "admission");
		adm.update_admission(driver, pin1);
		out.hcs(driver);
		
		log.hcs(driver, "nursing");
		Hcs_Nursing pack = new Hcs_Nursing();
		pack.validate(driver, pin1); 						//validate package of patient
		pack.discharge(driver, pin1); 						//fill up discharge instructions
		pack.pf(driver, pin1); 								//assign pf and discharge
		out.hcs(driver);
		
		//driver = d.startUp();
		log.hcs(driver, "billing"); 						//das discharge
		Hcs_Billing bill = new Hcs_Billing();
		bill.regular(driver, pin1); 
		out.hcs(driver);
	
		log.hcs(driver, "nursing"); 						//print gatepass
		pack.gatepass(driver, pin1);
		out.hcs(driver);
	}
	
	public void outpatient() throws Exception
	{		
		driver = d.startUp();
		log.admin(driver); 																									//login
		String returned_string = console.create_single_inpatient_with_no_pin_in_admin(driver, "outpatient",false);   		//update on admin and forward to hcs
		String[] arrString = returned_string.split(",");
		String lastName = arrString[0];
		String firstName = arrString[1];
		String admDate = arrString[2];

		String mainWindow = console.window_main_focus(driver);
		console.wellness_search_it(driver, lastName, firstName, admDate);
		console.get_status_and_click(driver, firstName, false);
		String text = m.set_dropdown_to_hcs("outpatient");
		console.select_dropdown_to_hcs(driver, text, "single");
		driver.switchTo().window(mainWindow);
		console.display_message_to_hcs(driver);
		console.wellness_search_it(driver, lastName, firstName, admDate);
		String pin1 = console.get_status_and_click(driver, "", false);
		act.goto_result_tracker(driver);
		act.tracker(driver, pin1);
		out.admin(driver);
		
		log.hcs(driver, "admission");
		adm.update_admission(driver, pin1);
		out.hcs(driver);
		
	}
	
	@SuppressWarnings({ "unused", "static-access" })
	public void pair() throws Exception{
		driver = twa.startUp("pair");
		mainWindow = driver.getWindowHandle();
		twa.mainWindow=mainWindow;
		driver.switchTo().frame(driver.findElement(By.name("patient1")));
		String returned_string = twa.fill_up_form(driver, "online", "inpatient", false);
		String[] arrString1 = returned_string.split(",");
		String lastName1 = arrString1[0];
		String firstName1 = arrString1[1];
		String admDate1 = arrString1[2];
		console.submit_form(driver);
		console.close_error_popup_after_submit_form(driver);
		for(int z=0; z<26; z++){
			driver.findElement(By.xpath("//input[@class='btnPrimary']")).sendKeys(Keys.ARROW_UP);	
		}
		driver.findElement(By.xpath("//a[@id='patientTwoTab']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.switchTo().frame(driver.findElement(By.name("patient2")));
		String returned_string2 = twa.patient_2_only(driver, "online", false);
		String[] arrString2 = returned_string2.split(",");
		String lastName2 = arrString2[0];
		String firstName2 = arrString2[1];
		twa.save_form(driver);
		console.wellness_search_it(driver, lastName1, firstName1, admDate1);
		console.get_status_and_click(driver, firstName1, false);
		String text = m.set_dropdown_to_hcs("queue");
		console.select_dropdown_to_hcs(driver, text, "pair");
		Thread.sleep(20000);
		console.display_message_to_hcs(driver);
		console.wellness_search_it(driver, lastName1, firstName1, admDate1);
		String pin = console.get_status_and_click(driver, "", false);
		System.out.println(pin);
		String[] pins = pin.split(",");
		pin1 = pins[0];
		pin2 = pins[1];
		out.admin(driver);		
		driver.close();
		
	}
	

}
